/**
 * 
 */
package com.itinsys.enma.util;
import org.springframework.beans.factory.annotation.Autowired;

import net.sf.ehcache.ObjectExistsException;

import com.itinsys.enma.dao.RoleDAO;
import com.itinsys.enma.domain.Role;
import com.itinsys.enma.service.PeriodDateChecker;
import com.itinsys.enma.service.ReservationDateChecker;
import com.itinsys.enma.service.SingletonService;
import com.itinsys.enma.service.impl.TimeChecker;

/**
 * @author pferraz
 *
 */
public class EnmaInit {
	

	@Autowired
	RoleDAO roleDAO;
	@Autowired
	SingletonService singletonService;
	@Autowired
	ReservationDateChecker reservDateCheckerService;
	@Autowired
	PeriodDateChecker periodDateCheckerService;

	public void initialize(){
		rolesInitialize();
		singletonService.init();
		reservDateCheckerService.checkReservationDates();
		periodDateCheckerService.checkPeriodDates();
		
		TimeChecker resTimeChecker=new TimeChecker(reservDateCheckerService,periodDateCheckerService);
		resTimeChecker.start();
	}
	
	public void rolesInitialize() {
		try {
			roleDAO.getById(1);
		} catch (ObjectExistsException o) {
			roleDAO.addRole(new Role(1, "Administrador"));
		}

		try {
			roleDAO.getById(2);
		} catch (ObjectExistsException o) {
			roleDAO.addRole(new Role(2, "Operador"));
		}
		try {
			roleDAO.getById(3);
		} catch (ObjectExistsException o) {
			roleDAO.addRole(new Role(3, "Basico"));
		}
	}
}
